#include "StdAfx.h"
#include "DataConversion.h"

DataConversion::DataConversion(void)
{
}

DataConversion::~DataConversion(void)
{
}

char* DataConversion::CStringToAnsi(const CString &m_ansi) 
{
	int nSize = m_ansi.GetLength();
	char *pAnsiString = new char[nSize+1];
	wcstombs(pAnsiString, m_ansi, nSize+1);
	return pAnsiString;
}


string DataConversion::CStringToStdString(CString str)
{
	CStringA stra(str.GetBuffer(0));
	string str_Tmp=stra.GetBuffer(0);
	stra.ReleaseBuffer();
	return str_Tmp;
}

CString DataConversion::StdStringToCString( string str )
{
	CString str_Tmp(str.c_str());
	return str_Tmp;
}


std::string DataConversion::HexToStdString( string str_hex )
{
	char buffer[3];
	sprintf(buffer, "%d", str_hex[0]);	
	return lexical_cast<string>(buffer);
}

int DataConversion::HexToInt( string str_hex )
{
	char buffer[3];
	sprintf(buffer, "%d", str_hex[0]);	
	return lexical_cast<int>(buffer);
}

